### 查询某篇故事的某个范围对应的文本

import os
import json

cur_dir = os.path.dirname(os.path.abspath(__file__))

# 读取 .txt 文件
def read_file(dir_path, filename):
    try:
        with open(os.path.join(dir_path, filename), 'r', encoding='utf-8') as f:
            return f.read()
    except Exception as e:
        print(f"Error reading file {filename}: {e}")
        return None

if __name__ == '__main__':

    # 读取的文件名
    filename = "../story/xiaohongmao.txt"

    # 指定的范围
    start_char_index = 2729
    end_char_index = 2734

    # 读取文件内容
    content = read_file(cur_dir, filename)

    # 打印指定范围内的文本
    print(f"第 {start_char_index} 到 {end_char_index} 个字符的文本是：{content[start_char_index:end_char_index]}")